package com.example.controller;

import com.example.pojo.WalletDetail;
import com.example.service.WalletDetailService;
import com.example.service.WalletService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/wallet")
@Slf4j
public class WalletController {

    @Autowired
    private WalletService walletService;


    @Autowired
    private WalletDetailService walletDetailService;


    //查询用户余额
    @GetMapping("/vacancy")
    public Double checkWalletMoney(Long id){
        log.info("id:{}",id);
        return walletService.checkWalletMoney(id);
    }

    //用户消费
    @GetMapping("/consume")
    public String userConsume(Long id,Double consumeMoney){
        log.info("money:{}",consumeMoney);
        String result = walletService.userConsume(id, consumeMoney);
        return result;
    }


    //用户退款
    @GetMapping("/refund")
    public String userRefund(Long id,Double refundMoney){
        log.info("money:{}",refundMoney);
        String result = walletService.userRefund(id, refundMoney);
        return result;
    }

    //查询用户钱包金额变动明细
    @GetMapping("/detail")
    public List<WalletDetail> moneyDetail(){
        List<WalletDetail> walletDetails = walletService.moneyDetail();
        return walletDetails;
    }
}
